#{extends 'main.html' /}
#{set title:'Students Home' /}

<h2>${course.toString()}</h2>
<p>${course.description.nl2br()}</p>
#{if sIn}
<h3>Assignments</h3>
<ul>
	#{list items:assignments, as:'assignment'}
	<li><a href="@{Show.assignment(assignment.id)}">${assignment.title}</a> (Deadline: <span class="formatTime">${assignment.deadline}</span>)</li>
	#{/list}
</ul>
#{/if}
#{else}
	<a href="javascript:;" onclick="$('#tutorials').toggle();">Join Course</a>
	<div id="tutorials" style="display:none;">
		#{if requested}You've requested to join ${requested.tutorial.toString()}. Requesting another tutorial will cancel the first request.#{/if}
		<form onsubmit="return join_course();">
		Tutorial: <select id="tutorial">
		#{list items:tutorials, as:'tut'}
			<option value="${tut.id}">${tut.number}</option>
		#{/list}
		</select> <input type="submit" value="Request Membership" />
		</form>
	</div>
#{/else}
<script type="text/javascript">
function join_course() {
	$.post('@{Ajax.joinCourse()}', 
			{tutorialId: $('#tutorials :selected').val() },
			function(){
				location.reload();
		});
	return false;
}
</script>